﻿<%@ page pageEncoding="UTF-8"%>
<%@include file="/util/tag.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <%@include file="../common/head.jsp" %>
  
     <script language="javascript" type="text/javascript">
            //保存成功的提示消息
            function showResult() {
                showResultDiv(true);
                window.setTimeout("showResultDiv(false);", 3000);
            }
            function showResultDiv(flag) {
                var divResult = document.getElementById("save_result_info");
                if (flag)
                    divResult.style.display = "block";
                else
                    divResult.style.display = "none";
            }
            $(function(){
            $("#adminForm").validate({
            	rules:{
            	"admin.name":"required",
            	"admin.telephone":"required",
            	"admin.rid":"required",
            	"admin.email":{required:true,email:true}
            	},messages:{
            		"admin.name":"请填写姓名",
            		"admin.telephone":"请填写电话号码",
            		"admin.rid":"至少选择一项",
            		"admin.email":{required:"请填写Email",email:"正确的 email 格式"}
            	},errorPlacement:function(error,element) {
	            		var p = $(element).parents("ul");
	            		if(p.length>0){
	            			element = p.eq(0).parent().eq(0);
	            		}
            		 error.appendTo(element.siblings(":last").addClass("error_msg"));
            	},success:function(label,element){
	            		var p = $(element).parents("ul");
	            		if(p.length>0){
	            			element = p.eq(0).parent().eq(0);
	            		}
            		 	$(element).siblings(":last").removeClass("error_msg").empty();
            		 }
            });
            	$('#save').click(function(){
            	if(!$("#adminForm").valid()) return;
            		var b=$("#adminForm").submitForm("update",
            			"保存失败，数据并发失败！",'保存成功!',$("#save_result_info"));
            			if(b){
            				$('#save_result_info').attr("class","save_success");
            			}else{
            				$('#save_result_info').attr("class","save_fail");
            			}
            			showResult();
            	});
            });
    </script>
    
    <body>
    
        <%@include file="../common/top.jsp"%>
        <div id="main">            
            <div id="save_result_info" class="save_success">保存成功！</div>
            <form action="update" method="post" id="adminForm" class="main_form">
            					<s:hidden name="admin.id"/>
                    <div class="text_info clearfix"><span>姓名：</span></div>
                    <div class="input_info">
                        <s:textfield name="admin.name"/>
                        <span class="required">*</span>
                        <div class="validate_msg_long "></div>
                    </div>
                    <div class="text_info clearfix"><span>管理员账号：</span></div>
                    <div class="input_info"><input type="text" readonly="readonly" class="readonly" value="${admin.code}"  /></div>
                    <div class="text_info clearfix"><span>电话：</span></div>
                    <div class="input_info">
                        <s:textfield name="admin.telephone"/>
                        <span class="required">*</span>
                        <div class="validate_msg_long"></div>
                    </div>
                    <div class="text_info clearfix"><span>Email：</span></div>
                    <div class="input_info">
                        <s:textfield name="admin.email" cssClass="width200"/>
                        <span class="required">*</span>
                        <div class="validate_msg_medium"></div>
                    </div>
                    <div class="text_info clearfix"><span>角色：</span></div>
                    <div class="input_info_high">
                        <div class="input_info_scroll">
                            <ul><s:if test="admin.hasRole(id)">checked</s:if>
                             <s:iterator value="roleList">
                                <li><input type="checkbox" name="admin.rid" value="${id}"
                                			<s:if test="admin.hasRole(id)">checked</s:if> />${name}</li>
                             </s:iterator>
                            </ul>
                        </div>
                        <span class="required">*</span>
                        <div class="validate_msg_tiny"></div>
                    </div>
                    <div class="button_info clearfix">
                        <input type="button" value="保存" class="btn_save" id="save" />
                        <input type="button" value="取消" class="btn_save" />
                    </div>
                </form>  
        </div>
        
        <%@include file="../common/bottom.jsp"%>
    </body>
</html>
